package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Slf4j
@Component
//@Aspect
public class MyAspect7 {

    @Pointcut("execution(* com.itheima.service.DeptService.*(..))")
    private void pt(){}

    @Before("pt()")
    public void before(JoinPoint joinPoint){
        log.info("MyAspect7 before...");
    }


    @Around("pt()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        log.info("MyAspect7 around before...");

        //获取目标对象类名
        String className = proceedingJoinPoint.getTarget().getClass().getName();
        log.info("目标对象类名"+className);

        //目标对象方法名
        String methodName = proceedingJoinPoint.getSignature().getName();
        log.info("目标对象方法名"+methodName);


        //获取目标对象运行时的传入的参数
        Object[] args = proceedingJoinPoint.getArgs();
        log.info("目标对象运行时的传入的参数"+ Arrays.toString(args));

        //放行 目标方法执行
        Object result = proceedingJoinPoint.proceed();

        //获取目标方法运行的返回值
        log.info("目标方法运行的返回值"+result);

        return result;
    }
}
